/**
 * Created by ren on 12/04/2017.
 */
import React, {Component} from 'react';
import {
  StyleSheet,
  Platform,
  Image,
  Dimensions,
  StatusBar,
  TouchableWithoutFeedback
}from 'react-native';
import {
  Container,
  Content,
  Input,
  Left,
  Icon,
  Body,
  Right,
  Button,
  Header,
  Title,
  Text,
  View
} from 'native-base'
import {getSize} from '../utils/response'
import PageUtil from '../utils/PageUtil'
import * as api from '../utils/api'
import * as Netservice from '../utils/netservice'
import Login from './Login'
export default class FindPwd extends Component {
  constructor(props) {
    super(props);
    this.state = {
      verBtn: '获取验证码',
      password: '',
      rePassword: ''
    }
    this.PageUtil = new PageUtil();
  }

  getCheckNum() {
    let num = 3
    let timer1 = setInterval(() => {
      this.setState({
        verBtn: '已发送(' + num + 's)'
      })
      if (num === 0) {
        clearInterval(timer1)
        this.setState({
          verBtn: '重新发送'
        })
        return
      }
      num--
    }, 1000)
  }

  _onPasswordChange(value) {
    this.setState({
      password: value
    })
  }

  _onRePasswordChange(value) {
    this.setState({
      rePassword: value
    })
  }

  updatePwd() {
    const {password, rePassword}=this.state
    if (!password) {
      Netservice.toast('密码不能为空')
      return
    }
    if (!rePassword) {
      Netservice.toast('重复密码不能为空')
      return
    }
    if (password !== rePassword) {
      Netservice.toast('两次输入密码不一致')
      return
    }
    Netservice.post(api.modifyBus, {
      phone: this.props.mobile,
      busPassword: password
    }).then(() => {
      this.PageUtil.resetTo(Login)
    })
  }

  render() {
    return (
      <Container style={{backgroundColor:'#F4F4F4'}}>
        <Header iosBarStyle="dark-content" backgroundColor="#F7F7F7"
                style={{backgroundColor:'#F7F7F7',height:Platform.OS==='ios'?getSize(64):getSize(50),borderBottomWidth:1,borderBottomColor:'#B2B2B2',marginBottom:getSize(7)}}>
          <StatusBar
            backgroundColor={'#303135'}
          />
          <Left style={{flex:1}}>
            <Button transparent onPress={this.PageUtil.pop}>
              <Icon name='arrow-back' style={{fontSize:getSize(24),color:'#333333'}}/>
            </Button>
          </Left>
          <Body style={{alignItems:'center'}}>
          <Title style={{color:'#333333',fontSize:getSize(19)}}>修改密码</Title>
          </Body>
          <Right style={{flex:1}}/>
        </Header>
        <View>
          <View style={{flexDirection:'row'}}>
            <Input placeholder='请输入新密码' style={styles.input1} secureTextEntry={true}
                   value={this.state.password}
                   onChangeText={(password) => this._onPasswordChange(password)}/>
          </View>
          <View style={{flexDirection:'row'}}>
          <Input placeholder='请输入确认新密码' secureTextEntry={true}
                 value={this.state.rePassword}
                 onChangeText={(rePassword) => this._onRePasswordChange(rePassword)}
                 style={styles.input1}/>
          </View>
          <Button
            block
            onPress={()=>this.updatePwd()}
            style={{marginLeft:getSize(15),marginRight:getSize(15),borderRadius: getSize(20),backgroundColor:'#16BD42',marginTop:getSize(42)}}
          >
            <Text style={{color:'white',fontSize:getSize(15)}}>确定</Text>
          </Button>
        </View>
      </Container>
    )
  }
}
const styles = {
  input1: {
    paddingLeft: getSize(10),
    marginLeft: getSize(18),
    marginRight: getSize(18),
    borderWidth: 1,
    marginTop: getSize(24),
    borderColor: '#C9C9C9',
    borderRadius: getSize(8),
    backgroundColor: 'white'
  }
}
